<extend name="Common@Layout:layui" />
<block name="title">
    <title>编辑权限</title>
</block>
<block name="style">
    <style>
        .layui-fixbar {
            display: none !important;
        }
        
        .img-wrap {
            width: 80px;
            height: 80px;
            display: table-cell;
            vertical-align: middle;
            text-align: center;
            cursor: pointer;
        }
        
        .img-wrap img {
            width: 100%;
            height: 100%;
        }
        
        .ul-level-0 li {
            line-height: 26px;
        }
        
        .ul-level-1,
        .ul-level-2,
        .ul-level-3,
        .ul-level-4 {
            padding-left: 30px;
        }
    </style>
</block>

<block name="main">
    <div class="layui-main" style="width:auto;padding:10px;">
        <form class="layui-form callback shuaxin" action="{:U('admin_auth_post')}" method="post">
            <php>
                $groups = C('AUTH_GROUP');

            </php>
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <foreach name="groups" item="vo" key="k">
                        <li <if condition="$k eq 'HOME'">class="layui-this"</if>>{$vo}</li>
                    </foreach>
                </ul>
                <div class="layui-tab-content">
                    <foreach name="groups" item="vo" key="k">
                        <div class="layui-tab-item <if condition=" $k eq 'HOME' ">layui-show</if>">
                            <?php 
                                $authRules = \Admin\Controller\AuthController::getdata_rule($k);
                                
                                $usrules = 0;
                                
                            	$map['id'] = $_GET['id'];
                            	$usrules = D('AuthGroup')->where($map)->getField('rules');
                            ?>
                            <ul class="ul-level-0">
                                <volist name="authRules" id="rule">
                                    <php>echo \Admin\Controller\AuthController::show_rule($rule,0,$usrules);</php>
                                </volist>
                            </ul>
                        </div>
                    </foreach>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" value="{$info['id']}" name="id">
                    <button class="layui-btn" lay-submit lay-filter="auth">立即提交</button>
                </div>
            </div>
        </form>

    </div>
</block>


<block name="script">
    <script>
        layui.use(['jquery', 'element', 'form', 'layer'], function() {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;

            form.on('checkbox(rule)', function(data) {
                if (data.elem.checked) {
                    $(this).parent().find('input').prop('checked', 'checked');
                } else {
                    $(this).parent().find('input').removeAttr("checked");
                }
                form.render(); //刷新
            });

            form.on('submit(auth)', function(data) {
            	
                ii = layer.msg('Loading...', {
                    icon: 16,
                    time: 10000
                });


                $.post($('form').attr('action'), $("form").serialize(), function(ret) {
                    layer.close(ii);
                    layer.msg(ret.info, {
                        icon: 1,
                        time: 1000
                    });
                    setTimeout(function() {
                        parent.close_iframe_dialog();
                    }, 1000);

                });
                return false;
            });
        });
    </script>
</block>